package com.yousu.dashijixm.controller;

import com.yousu.dashijixm.pojo.Category;
import com.yousu.dashijixm.pojo.Result;
import com.yousu.dashijixm.service.CategoryService;
import com.yousu.dashijixm.service.impl.CategoryServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: YouSu
 * @Version: 1.0
 * @CreateTime: 2023-11-21  10:49
 * 文章分类
 */
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @PostMapping //新增文章分类接口
    public Result category(@RequestBody @Validated Category category){
        categoryService.add(category);
        return Result.success();
    }
    @GetMapping //获取文章分类接口
    public Result<List<Category>> list(){
        List<Category> cs = categoryService.list();
        return Result.success(cs);
    }

    @GetMapping("/detail") //获取文章详细分类信息接口
    public Result<Category> detail( Integer id){
        Category c =categoryService.findById(id);
        return Result.success(c);
    }

    @PutMapping //更新分类信息接口
    public Result update(@RequestBody @Validated(Category.Update.class) Category category){
         categoryService.update(category);
        return Result.success();
    }
    @DeleteMapping
    public Result delete(Integer id){
        categoryService.delete(id);
        return Result.success();
    }
}
